// pages/caseApply/caseApply.js
import request from '../../../utils/config.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: '',
    caseAmt: '',
    caseMemo: '',
    isSlideDown:false,
    this_caseBizMode: '',
    this_diagnosisSign: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  getTextareaValue: function(e) {
    // console.log(e.detail.value)
    this.setData({
      caseMemo: e.detail.value
    })
  },
  userNameInput: function(e) {
    this.setData({
      userName: e.detail.value
    })
  },
  caseAmtInput: function(e) {
    this.setData({
      caseAmt: e.detail.value
    })
  },
  // 开始提交申请
  startSubInfo: function() {
    if (!this.data.userName) {
      wx.showToast({
        title: '请输入当事人',
        icon: 'none'
      })
      return;
    }
    if (!this.data.caseAmt) {
      wx.showToast({
        title: '请输入正确的涉案金额',
        icon: 'none'
      })
      return;
    } else if (isNaN(this.data.caseAmt * 1)) {
      wx.showToast({
        title: '涉案金额格式不正确',
        icon: 'none'
      })
      return;
    }
    // if (app.globalData.sessionId) {
      this.subCaseApplyInfo();
    // } else {
    //   this.setData({
    //     isSlideDown: true
    //   })
    // }
  },
  subCaseApplyInfo: function() {
    var headerInfo = {}, bizInfo = {};
    headerInfo.pageNum = '';
    headerInfo.pageSize = '';
    headerInfo.sessionId = app.globalData.sessionId;

    if (app.globalData.userType == "1") {
      this.data.this_caseBizMode = '1';
      this.data.this_diagnosisSign = '1';
    } else {
      this.data.this_caseBizMode = '2';
      this.data.this_diagnosisSign = '1';
    }
    

    bizInfo.caseAmt = this.data.caseAmt + '';
    bizInfo.caseMemo = this.data.caseMemo || '';
    bizInfo.caseMemo = bizInfo.caseMemo.replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, "");
    bizInfo.applyUserName = this.data.userName;
    bizInfo.caseBizMode = this.data.this_caseBizMode + '';
    bizInfo.diagnosisSign = this.data.this_diagnosisSign + '';
    // console.log(bizInfo);
    wx.showLoading({ title: '',mask: true })
    request.requestLogin_api("simpleSubmitCaseInfo", headerInfo, bizInfo, (tempData) => {//SUCCESS
        console.log("提交申请数据成功=", tempData);
        wx.hideLoading()
        if (tempData.data.isSuccess == 'T') {
          setTimeout(function() {
            wx.navigateTo({
              url: '../lawsuitInvestSuccess/lawsuitInvestSuccess',
            })
          },100)
        } else {
          wx.showToast({
            title: tempData.errMsg,
            icon: 'none'
          })
        }
      }, (data)=> {
        if (data != "") {//FAIL
          wx.hideLoading()
          if (data.errorCode == ERROR_CODE.noLogin) {
            FIREFLY("", data.errorMsg, "", function () {
              //调用退出登录
              transData.mobileNo = "";
              transData.password = "";
              transData.sessionId = "";
              transData.userType = "";
              resultData.loginUserData = "";
              // $timeout(function(){
              //     $scope.$emit("goNext","/mine");
              // },0);
            });
          } else {
            wx.showToast({
              title: data.errorMsg,
              icon: 'none'
            })
          }
        } else {
          wx.hideLoading()
          wx.showToast({
            title: '连接超时',
            icon: 'none'
          })
        }
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})